//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class LayoutNode: IOfficeXmlSerializable
    {
        private string _name;
        private string _styleLbl;
        private ChildOrderType _chOrder;
        private string _moveWith;
        private List<IOfficeXmlSerializable> _items = new List<IOfficeXmlSerializable>();

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("layoutNode"))
            {
                _name = c.GetOptionalString("name", string.Empty);
                _styleLbl = c.GetOptionalString("styleLbl", string.Empty);
                _chOrder = c.GetOptionalEnum("chOrder", ChildOrderType.Bottom);
                _moveWith = c.GetOptionalString("moveWith", string.Empty);
                _items.Clear();
                _items.AddRange(ReaderHelper.ReadItems(c));
            }

        }

        
        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("layoutNode"))
            {
                c.SetOptionalString("name", _name, string.Empty);
                c.SetOptionalString("styleLbl", _styleLbl, string.Empty);
                c.SetOptionalEnum("chOrder", _chOrder, ChildOrderType.Bottom);
                c.SetOptionalString("moveWith", _moveWith, string.Empty);
                c.WriteElements(_items);
            }
        }
    }
}